Repository navigation
fix(agc): clamp an exported pixel depth to the viewport depth range - #10348
Conversation
The DB clamps a pixel shader's exported depth to PA_SC_VPORT_ZMIN_0 and ZMAX_0 unless DB_RENDER_OVERRIDE.DISABLE_VIEWPORT_CLAMP is set. Vulkan only clamps with depthClamp, which also drops clipping, so the exported value reached the depth attachment unclamped. The pixel stage info now carries the two bounds when the shader exports depth (0 and 1 otherwise), and the exported value is NClamped to them before it is stored to gl_FragDepth. With DISABLE_VIEWPORT_CLAMP the value is stored as exported; non-finite or inverted bounds are rejected. DB_RENDER_OVERRIDE joins the draw key registers. The bounds are part of the recompile cache key (only for depth-exporting shaders, so other keys do not change), the draw key and its register check, and recompile requests (serialization version 47). Tests: the pixel stage decode reads the bounds, passes the disable flag through and rejects bad bounds, and leaves a draw without depth export at 0 and 1; a recompiled depth export stores the NClamped value, and its bounds survive serialization and key the cache. Request version 47: main is at 44 (boykopovar#8612) and open PRs also claim 44 to 46 (boykopovar#8564, boykopovar#7888, boykopovar#9193 and the boykopovar#9020, boykopovar#9335, boykopovar#9748 stack). Whichever of these lands second renumbers.
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
MarcZX10
left a comment
There was a problem hiding this comment.
The reported RTX 4090 run covers the changed head, but this PR changes both the AGC driver and shader recompiler. CONTRIBUTING requires the same focused tests on main and this change, on the same machine and GPU, with VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1, and ANYPS5_REQUIRE_VULKAN=1, plus confirmation that the requested layer loaded and a comparison showing no new VUID- errors. Please add those baseline/change results (including the depth-export test and relevant serializer coverage) before merge. I could not dispatch the repository's manual build workflow from this account; GitHub returned HTTP 403 because workflow dispatch requires repository admin rights. My local configure also cannot reach the test build: this checkout has no SDL2 submodule sources and the host lacks XRandR development support, so I did not run the product tests.
adriadam10
left a comment
There was a problem hiding this comment.
The change reads right: the exported value is NClamped to PA_SC_VPORT_ZMIN_0/ZMAX_0 unless DB_RENDER_OVERRIDE bit 16 is set, the bounds key the draw, the recompile cache (depth-exporting shaders only) and the serializer, and the new tests fail without the clamp. Two things block it:
- It conflicts with
main, which now writes request version 46 (#8564:targetMergefields at the end ofreadPixelInfo/writePixelInfo). The bounds must be written and read after thetargetMergeblock, gated onversion >= 47, and the version fixtures inRequestSerializerTests.cppandShaderMemory.cpp(base64 prefixes, the byte-stripping legacy fixtures, "future version") need redoing on top of 46. Conflicts are inRequestSerializer.cpp,ShaderMemory.cppandRequestSerializerTests.cpp. - @MarcZX10's change request is still open: CONTRIBUTING needs the same focused tests (
agc_driver_depth_export_clamp,agc_shader_memory,request_serializer, the depth tests) onmainand on this branch, same machine and GPU, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, confirmation that the layer loaded, and a comparison showing no newVUID-errors. Please add those logs toTestedafter rebasing.
A pixel shader that exports depth now reads DB_RENDER_OVERRIDE and the viewport depth bounds (PA_SC_VPORT_ZMIN_0 and ZMAX_0) while its stage info is decoded. The stencil replay test builds its context registers by hand and left them out, so the decode threw "missing register at DWORD 0x3" for its depth-exporting shader. The test now sets the override off and the bounds to 0 and 1, which is what the decode produced before the clamp.
|
Windows run of this head
AI-assisted: yes (Claude Code) |
|
First Windows run of the device test, and the first on AMD. Windows 11 10.0.26300, WinLibs GCC 15.2.0, Release; this head
AI-assisted: yes (Claude Code); results above were run on this machine. |
adriadam10
left a comment
There was a problem hiding this comment.
The rebase onto version 46 reads right: the bounds are written after the targetMerge block, read with version >= 47, and the fixtures were redone. @wachi35676's control run (main's emitter with the rest of this PR) fails agc_driver_depth_export_clamp and agc_shader_memory on NVIDIA and AMD, so the tests cover the clamp. Two things are left:
- @MarcZX10's request is still open and nobody has supplied it: CONTRIBUTING needs the same focused tests (
agc_driver_depth_export_clamp,agc_shader_memory,request_serializer, the depth tests) onmainand on this head, same machine and GPU, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, confirmation that the layer loaded (nowas not found but was requested by env var VK_INSTANCE_LAYERSin either log), and a comparison showing no newVUID-errors. The Windows runs above don't use the layer. Please add those logs toTested. - The description is out of date: it says main is at version 45 and that this writes 46/47 with other PRs holding 46. Main is at 46 now and this branch writes 47 after its fields. Please correct
Whatand updateTestedwith the run on the current head.
Also, as wachi35676 noted, only PA_SC_VPORT_ZMIN_0/ZMAX_0 are read, so a draw that selects another viewport is clamped to viewport 0's range; please add a line for that in docs/dev/debt/ for the AGC driver.
The clamp reads PA_SC_VPORT_ZMIN_0 and PA_SC_VPORT_ZMAX_0 only, so a draw that selects another viewport is clamped to viewport 0's depth range.
…on 48 Main took request serialization version 47 for the two-sample dithered alpha-to-coverage value. The depth export clamp bounds are now written at version 48 and read only for versions from 48, so a version 47 request as main writes it still decodes, with default bounds. Tests: version 48 is the emitted prefix, 49 the first unsupported one, and a version 47 two-sample dithered request (with and without depth export) decodes as written.
require takes a C string; the version 46 and 47 depth export messages were built with std::string and did not compile.
…on 49 Main took request serialization version 48 for the fragment barycentric built-ins flag (boykopovar#9193). The depth export clamp bounds are now written at version 49 and read only for versions from 49, so a version 48 request as main writes it still decodes, with default bounds. Tests: version 49 is the emitted prefix, 50 the first unsupported one, a depth exporting request without its bounds decodes at 48, 47 and 46 (the last two without main's barycentric byte), and a version 48 two-sample dithered request decodes as written.
|
@adriadam10 thanks, all three are done on the current head
The description is updated to match. |
# Conflicts: # docs/dev/debt/libSceAgcDriver.md
All three points are addressed on the current head (description at v49, validation-layer Tested table, viewport 0 debt line); see the reply above. Dismissing so the merge check can run; happy to revisit if anything is still open.
What
A pixel shader that exports depth now has the exported value clamped to the viewport depth range before it reaches the depth attachment, as the DB does.
PA_SC_VPORT_ZMIN_0andZMAX_0when the shader exports depth (0 and 1 otherwise), and the recompiled shaderNClamps the exported value to them before it storesgl_FragDepth. Only viewport 0 bounds the clamp.DB_RENDER_OVERRIDE.DISABLE_VIEWPORT_CLAMPset, the value is stored as exported. Non-finite or inverted bounds are rejected.DB_RENDER_OVERRIDEjoins the draw key registers.The DB clamps an exported depth to
ZMIN/ZMAXunless the override disables it. Vulkan only clamps withdepthClamp, which also turns off clipping, so until now the exported value reached the depth attachment unclamped.This writes recompile request version 49 and reads the depth bounds from version 49 on. Main is at version 48 (the barycentric built-ins flag from #9193); this branch keeps main's version-48 fields and adds the bounds after them. Version 46, 47 and 48 requests still decode, with default depth bounds.
Tested
Head
d4a296d863(maind13b3d7c55merged in), compared with maind13b3d7c55, same machine, NVIDIA GeForce RTX 4090 (driver 610.57.04, Vulkan 1.4.341), Linux, Release build,ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Khronos validation layer 1.4.363) andVK_LOADER_DEBUG=layer, so each log shows the loader inserting the layer. Tests selected:agc_driver_depth_export_clamp,agc_shader_memory,request_serializer,agc_driver_graphics,agc_masked_selectand every test withdepthin its name.d13b3d7c55d4a296d863Insert instance layer "VK_LAYER_KHRONOS_validation"(loader lines)was not found but was requestedVUID-linesThere are a couple more inserted-layer lines than tests because some tests create more than one Vulkan instance.
The extra passing test on the head is
agc_driver_depth_export_clamp, which does not exist on main. It runs on the device.agc_driver_depth_export_clampandagc_shader_memoryfail, so the tests cover the clamp.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository